package com.myanalytic.olap.impl;

import java.util.ArrayList;
import java.util.List;

import com.myanalytic.olap.CrossTable;
import com.myanalytic.olap.TableData;

public class CrossTableImpl implements CrossTable{

	//simple implementation
	private List<List> data;
	private List axisColumn;
	private List axisRow;
	
	
	
	public CrossTableImpl(List<List> data, List axisColumn, List axisRow) {
		super();
		this.data = data;
		this.axisColumn = axisColumn;
		this.axisRow = axisRow;
	}

	public int getColumnCount() {
		return axisColumn.size();
	}

	public int getRowCount() {
		return axisRow.size();
	}

	public TableData getTableData(int rowStart, int rowEnd, int columnStart, int columnEnd) {
		TableData tableData = new TableData();
		tableData.setColumns(axisColumn.subList(columnStart, columnEnd));
		tableData.setRows(axisRow.subList(rowStart, rowEnd));
		List<List> resultData = new ArrayList<List>(rowEnd-rowStart);
		for(int i=rowStart; i<=rowEnd; ++i) {
			resultData.add(data.subList(columnStart, columnEnd));
		}
		tableData.setData(resultData);
		
		return tableData;
	}

}
